<template>
  <el-dialog
     v-drag
    :title="!dataForm.auditId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :inline="true" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="产品ID" prop="productId">
      <el-input size="mini"  v-model="dataForm.productId" placeholder="产品ID" clearable></el-input>
    </el-form-item>
    <el-form-item label="采购审核状态 0未审核， 1审核通过， -1审核不通过" prop="purchaseAuditState">
      <el-input size="mini"  v-model="dataForm.purchaseAuditState" placeholder="采购审核状态 0未审核， 1审核通过， -1审核不通过" clearable></el-input>
    </el-form-item>
    <el-form-item label="采购人id" prop="purchaseAuditUserId">
      <el-input size="mini"  v-model="dataForm.purchaseAuditUserId" placeholder="采购人id" clearable></el-input>
    </el-form-item>
    <el-form-item label="采购员名称" prop="purchaseAuditUserName">
      <el-input size="mini"  v-model="dataForm.purchaseAuditUserName" placeholder="采购员名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="采购审核日期" prop="purchaseAuditDate">
      <el-input size="mini"  v-model="dataForm.purchaseAuditDate" placeholder="采购审核日期" clearable></el-input>
    </el-form-item>
    <el-form-item label="采购审核说明" prop="purchaseAuditRemark">
      <el-input size="mini"  v-model="dataForm.purchaseAuditRemark" placeholder="采购审核说明" clearable></el-input>
    </el-form-item>
    <el-form-item label="质管审核状态 0未审核， 1审核通过， -1审核不通过" prop="qcAuditState">
      <el-input size="mini"  v-model="dataForm.qcAuditState" placeholder="质管审核状态 0未审核， 1审核通过， -1审核不通过" clearable></el-input>
    </el-form-item>
    <el-form-item label="质管人id" prop="qcAuditUserId">
      <el-input size="mini"  v-model="dataForm.qcAuditUserId" placeholder="质管人id" clearable></el-input>
    </el-form-item>
    <el-form-item label="质管员名称" prop="qcAuditUserName">
      <el-input size="mini"  v-model="dataForm.qcAuditUserName" placeholder="质管员名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="质管审核日期" prop="qcAuditDate">
      <el-input size="mini"  v-model="dataForm.qcAuditDate" placeholder="质管审核日期" clearable></el-input>
    </el-form-item>
    <el-form-item label="质管审核说明" prop="qcAuditRemark">
      <el-input size="mini"  v-model="dataForm.qcAuditRemark" placeholder="质管审核说明" clearable></el-input>
    </el-form-item>
    <el-form-item label="质保审核状态 0未审核， 1审核通过， -1审核不通过" prop="qaAuditState">
      <el-input size="mini"  v-model="dataForm.qaAuditState" placeholder="质保审核状态 0未审核， 1审核通过， -1审核不通过" clearable></el-input>
    </el-form-item>
    <el-form-item label="质保人id" prop="qaAuditUserId">
      <el-input size="mini"  v-model="dataForm.qaAuditUserId" placeholder="质保人id" clearable></el-input>
    </el-form-item>
    <el-form-item label="质保员名称" prop="qaAuditUserName">
      <el-input size="mini"  v-model="dataForm.qaAuditUserName" placeholder="质保员名称" clearable></el-input>
    </el-form-item>
    <el-form-item label="质保审核日期" prop="qaAuditDate">
      <el-input size="mini"  v-model="dataForm.qaAuditDate" placeholder="质保审核日期" clearable></el-input>
    </el-form-item>
    <el-form-item label="质保审核说明" prop="qaAuditRemark">
      <el-input size="mini"  v-model="dataForm.qaAuditRemark" placeholder="质保审核说明" clearable></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="visible = false">取消</el-button>
      <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          auditId: 0,
          productId: '',
          purchaseAuditState: '',
          purchaseAuditUserId: '',
          purchaseAuditUserName: '',
          purchaseAuditDate: '',
          purchaseAuditRemark: '',
          qcAuditState: '',
          qcAuditUserId: '',
          qcAuditUserName: '',
          qcAuditDate: '',
          qcAuditRemark: '',
          qaAuditState: '',
          qaAuditUserId: '',
          qaAuditUserName: '',
          qaAuditDate: '',
          qaAuditRemark: ''
        },
        dataRule: {
          productId: [
            { required: true, message: '产品ID不能为空', trigger: 'blur' }
          ],
          purchaseAuditState: [
            { required: true, message: '采购审核状态 0未审核， 1审核通过， -1审核不通过不能为空', trigger: 'blur' }
          ],
          purchaseAuditUserId: [
            { required: true, message: '采购人id不能为空', trigger: 'blur' }
          ],
          purchaseAuditUserName: [
            { required: true, message: '采购员名称不能为空', trigger: 'blur' }
          ],
          purchaseAuditDate: [
            { required: true, message: '采购审核日期不能为空', trigger: 'blur' }
          ],
          purchaseAuditRemark: [
            { required: true, message: '采购审核说明不能为空', trigger: 'blur' }
          ],
          qcAuditState: [
            { required: true, message: '质管审核状态 0未审核， 1审核通过， -1审核不通过不能为空', trigger: 'blur' }
          ],
          qcAuditUserId: [
            { required: true, message: '质管人id不能为空', trigger: 'blur' }
          ],
          qcAuditUserName: [
            { required: true, message: '质管员名称不能为空', trigger: 'blur' }
          ],
          qcAuditDate: [
            { required: true, message: '质管审核日期不能为空', trigger: 'blur' }
          ],
          qcAuditRemark: [
            { required: true, message: '质管审核说明不能为空', trigger: 'blur' }
          ],
          qaAuditState: [
            { required: true, message: '质保审核状态 0未审核， 1审核通过， -1审核不通过不能为空', trigger: 'blur' }
          ],
          qaAuditUserId: [
            { required: true, message: '质保人id不能为空', trigger: 'blur' }
          ],
          qaAuditUserName: [
            { required: true, message: '质保员名称不能为空', trigger: 'blur' }
          ],
          qaAuditDate: [
            { required: true, message: '质保审核日期不能为空', trigger: 'blur' }
          ],
          qaAuditRemark: [
            { required: true, message: '质保审核说明不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.auditId = id || 0
        this.visible = true
        this.$nextTick(async () => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.auditId) {
            const res = await this.$http({
              url: `/product/audit/info/${this.dataForm.auditId}`,
              method: 'get',
              params: this.$http.adornParams()
            })
                let data = res.data
                if (data && data.code === 0) {
                    this.dataForm = data.baseProductAudit
                }
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate(async (valid) => {
          if (valid) {
            const res = await this.$http({
              url:`/product/audit/${!this.dataForm.auditId ? 'save' : 'update'}`,
              method: 'post',
             data: this.$http.adornData( this.dataForm)
            })
            let data = res.data
            if (data && data.code === 0) {
                this.$message({
                        message: '操作成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                }
            })
            } else {
                this.$message.error(data.msg)
            }
          }
        })
      }
    }
  }
</script>
